
class A:
    def __init__(self,i):
        print('init函数')
        self.i = i

    def __call__(self, i):
        print("调用了call函数")
        return B(self,C(i))

class C:
    def __init__(self,i):
        self.i = i
        # print(i)

class B:
    def __init__(self,session,c:C):
        self.session = session
        print("object"+ str(self.session))
        print("222")
        self.c = c
        print("object"+str(session.i))

# a = A(1)                    # 只有 init函数
# a(1)                       # 在实例中传入函数的个数是和call方法相匹配
# 调用了call函数
# object<__main__.A object at 0x10985bcd0>
# 222
# object1


A(2)
# print(a.i)



# class A():
#
#     # def __getattr__(self, method):
#     #     self.method = method  # jsonrpc function name
#     #     print(self.method)    # 一个是a1 一个是waitForExists
#     #     return self
#     #
#     # def __call__(self, *args, **kwargs):
#     #     # print(self.method)        # 只有一个是waitForExists
#     #     return 2
#
#     @property
#     def a1(self):
#         class B():
#             def __init__(self, i):
#                 self.i = i
#                 self.method = None
#                 self.d: 2 = None
#
#             def __getattr__(self, method):
#                 self.method = method  # jsonrpc function name
#                 print(self.method)
#                 return self
#
#             def __call__(self, *args, **kwargs):
#                 print(self.d)
#                 print(1)
#                 return True
#         return B(self)
#
#
# a = A()
# b = a.a1.waitForExists(1,5)
# c = a.wait(3)
# print(b)
# print(c)
# print(b.method)


# class A:
#     def __init__(self,i):
#         self.i = i
#         self.method = None
#
#
#     def jsonrpc(self):
#         class JSONRpcWrapper():
#             def __init__(self, server):
#                 self.server = server
#                 self.method = None
#
#             def __getattr__(self, method):
#                 self.method = method  # jsonrpc function name
#                 return self
#
#             def __call__(self, *args, **kwargs):
#                 print("调用了call函数")
#                 HTTP_TIMEOUT = "10"
#                 http_timeout = kwargs.pop('http_timeout', HTTP_TIMEOUT)
#                 params = args if args else kwargs
#                 return self.server._jsonrpc_retry_call(self.method, params,
#                                                       http_timeout)
#         return JSONRpcWrapper(self)
#
#
#     def _jsonrpc_retry_call(self, *args, **kwargs):
#         return self._jsonrpc_call(*args, **kwargs)
#
#     def _jsonrpc_call(self, method, params=[], http_timeout=60):
#         return method
#
# a = A(1)
# b = a.jsonrpc.waitForExists(a, int(1000), http_timeout=10)